package com.els.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class JsonUtil {
	public String ReadFile(String Path){
		BufferedReader reader = null;
		String laststr = "";
		try{
			FileInputStream fileInputStream = new FileInputStream(Path);
			InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
			reader = new BufferedReader(inputStreamReader);
			String tempString = null;
			while((tempString = reader.readLine()) != null){
				laststr += tempString;
//				System.out.println(tempString);
				
			}
//			System.out.println(laststr.equals(""));
			reader.close();
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			if(reader != null){
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return laststr;
	}
	public static JsonObject traslateToJson(String path){
		
		JsonUtil ju=new JsonUtil();
		String str=ju.ReadFile(path);
		JsonObject jo=null;
		try{
			jo=new Gson().fromJson(str,JsonObject.class);
		}catch(Exception e){
			System.out.println(path+":null json");
		}
		return jo;
	}

}
